package com.twentyfour.controller;

import com.twentyfour.pojo.GameInformation;
import com.twentyfour.pojo.RefereeScore;
import com.twentyfour.service.AdminServiceImpl;
import com.twentyfour.service.LeaderServiceImpl;
import com.twentyfour.service.RefereeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
public class RefereeController {

    @Autowired
    @Qualifier("AdminServiceImpl")
    AdminServiceImpl adminService;

    @Autowired
    @Qualifier("LeaderServiceImpl")
    LeaderServiceImpl leaderService;

    @Autowired
    @Qualifier("RefereeServiceImpl")
    RefereeServiceImpl refereeService;

    @RequestMapping("/updateRefereeScore")
    public void updateRefereeScore(HttpServletResponse response, HttpServletRequest request,Integer score,
                                   Integer certainId,Integer certainRefereeId) throws IOException {

        List<RefereeScore> refereeScores = refereeService.queryAllItemsByRefereeId(certainRefereeId);
        for (RefereeScore refereeScore:refereeScores){
            if (refereeScore.getId().equals(certainId)){
                refereeScore.setScore(score);
                refereeService.updateRefereeScore(refereeScore);
            }
        }



        response.sendRedirect(request.getContextPath()+"/toGrade");
    }



}
